<?php

/*
 * activite/load-index.phtml
 * Affichage de la liste des Codes activités
 */
?>
<?php
$title		 = "Code d'Activités";
$this->headTitle($title);
// Variables
$codeList	 = $this->codeList;
?>
<div class='content-body'>
    <div class='list-container'>
	<table class="table table-striped list-table">
	    <thead>
		<tr>
		    <td width="10%">Code</td>
		    <td width="25%">Libellé</td>
		    <td width="20%">Couleur</td>
		    <td width="35%">Description</td>
		    <td width="10%">&nbsp;</td>
		</tr>
	    </thead>
	    <tbody>
		<?php foreach ($codeList as $code): ?>
    		<tr>
		    <td style="text-align: center;">
			<a href='#' id='code-<?php echo $code->id; ?>' class="edit-code" data-name="code" data-pk="<?php echo $code->id; ?>" data-type='text'>
				<?php echo $code->code; ?>
    			</a>
    		    </td>
		    <td style="text-align: center;">
			<a href='#' id='libelle-<?php echo $code->id; ?>' class="edit-libelle" data-name="libelle" data-pk="<?php echo $code->id; ?>" data-type='text'>
				<?php echo $code->libelle; ?>
    			</a>
    		    </td>
		    <td style="text-align: center;">
			<input type='text' id='couleur-<?php echo $code->id; ?>' class="edit-couleur" value='<?php echo $code->couleur; ?>' data-pk="<?php echo $code->id; ?>" style='background: <?php echo $code->couleur; ?>; text-indent: -999px; width: 48px'>
    		    </td>
		    <td style="text-align: center;">
			<a href='#' id='description-<?php echo $code->id; ?>' class="edit-description" data-name="description" data-pk="<?php echo $code->id; ?>"  data-type='textarea'>
				<?php echo $code->description; ?>
    			</a>
    		    </td>
		    <td>
    			<a href='#' id='delete-<?php echo $code->id; ?>' onclick='return erase(<?php echo $code->id; ?>);'>
    			    <img src='<?php echo $this->basePath() . '/img/rhx/delete-16x16.png' ?>' alt='Effacer' title='Effacer'>
    			</a>
    		    </td>
    		</tr>
		<?php endforeach; ?>
	    </tbody>
	</table>
    </div>
</div>

<script type="text/javascript">
// Démarrage
$(function(){
    $('.edit-code').editable({
	title: 'Edition du Code',
	url : '<?php echo $this->url('RHX/default', array('controller'	 => 'activite', 'action'	 => 'saveStringData')) ?>'
    });
    $('.edit-libelle').editable({
	title: 'Edition du Libellé',
	url : '<?php echo $this->url('RHX/default', array('controller'	 => 'activite', 'action'	 => 'saveStringData')) ?>'
    });
    $('.edit-description').editable({
	title: 'Edition de la Description',
	url : '<?php echo $this->url('RHX/default', array('controller'	 => 'activite', 'action'	 => 'saveStringData')) ?>'
    });
    $('.edit-couleur').spectrum({
	    disabled: false,
	    flat: false,
	    showInput : true,
	    showInitial: true,
	    chooseText: "Sélectionner",
	    cancelText: "Annuler",
	    preferredFormat: "hex6",
	    showSelectionPalette: true,
	    localStorageKey: "spectrum.homepage",
	    clickoutFiresChange: true,
	    move: function(color) {
		$('#edit-couleur').val(color.toHexString());
	    },
	    hide: function(color){
		pk = $(this).attr('data-pk');
		ajax = $.ajax({
		    type: 'post',
		    url : '<?php echo $this->url('RHX/default', array('controller'	 => 'activite', 'action'	 => 'saveStringData')) ?>',
		    data: '&pk=' + pk + '&name=couleur&value=' + color.toHexString()
		});
		ajax.done(function(result){
		    if(!result.done){
			alert("Une erreur est survenue lors de la mise à jour de la couleur");
		    }
		});
		ajax.fail(function(){
		    alert("Une erreur est survenue lors de la mise à jour de la couleur");
		});
	    }
	});
});
</script>

